<?php

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\Controller;
use App\Models\Help;
use Illuminate\Http\Request;

class HelpController extends Controller
{
    public function getHelpPageRows(Request $request){
        $status = intval($request->input('status'));
        $title = strval($request->input('title'));
        $query = Help::orderBy('id','ASC');
        if($title){
            $query->where('title','like',"%{$title}%");
        }
        if($status){
            $query->where('status',$status);
        }
        $rows =$query->paginate(20);
        foreach($rows as $row){
            # 替换空格和换行
            $pattern = array(
                '/ /',//半角下空格
                '/　/',//全角下空格
                // '/\r\n/',//window 下换行符
                // '/\n/',//Linux && Unix 下换行符
            );
            $replace = array('&ensp;','&ensp;');
            $row->content = preg_replace($pattern, $replace, $row->content);
        }
        $data =[
            'rows'=>$rows,
        ];
        return response()->json(['code' => 1,'msg' => 'Success','data' => $data]);
    }
}
